使用 ifconfig 查看本机 ip 您所在的位置:网站首页 ifconfig -a命令详解 使用 ifconfig 查看本机 ip

使用 ifconfig 查看本机 ip

2023-09-05 15:19| 来源: 网络整理| 查看: 265

在终端中使用 ifconfig 可以查看本地 ip

在终端中输入 ifconfig 可以看到很多的信息,其中包含了本机的 ip,但是信息过多,及时你知道从哪查找,每次看也会头晕,我们需要的精确找到本机 ip 的方法。

在 Linux 中使用命令

$ ifconfig eth0 eth0: flags=4163 mtu 1500 inet 172.17.8.241 netmask 255.255.240.0 broadcast 172.17.15.255 ether 00:16:3e:0c:ec:10 txqueuelen 1000 (Ethernet) RX packets 215013189 bytes 59080762287 (55.0 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 125960779 bytes 124345275246 (115.8 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

第二行的第一个 ip 就是本机 ip 172.17.8.241

在 MaxOS 中稍有不同,命令为

$ ifconfig en0

接下来我们使用 grep awk 来进行精准获取

CentOS ifconfig eth0 | grep inet | grep -v inet6 | awk '{print $2}' Ubuntu ifconfig eth0 | grep inet | grep -v inet6 | awk '{print $2}' | awk -v FS=":" '{print $2}' MacOS ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}'

原文链接:http://wxnacy.com/2018/10/23/ifconfig-ip/



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有